package bma.common.netty.protobuf.common;

import java.util.List;

import bma.common.netty.protobuf.common.impl.PRequestFilterPipeline;
import bma.common.netty.protobuf.core.PRequestContext;
import bma.common.netty.protobuf.core.impl.PServiceBase;

public class PServiceCommon extends PServiceBase {

	protected PRequestFilterPipeline filterPipeline = new PRequestFilterPipeline() {

		@Override
		public boolean processRequest(PRequestContext ctx) {
			return afterProcessFilters(ctx);
		}
	};

	public PRequestFilterPipeline getFilterPipeline() {
		return filterPipeline;
	}

	public void setFilter(PRequestFilter f) {
		filterPipeline.addLast("Filter" + System.identityHashCode(f), f);
	}

	public void setFilters(List<PRequestFilter> list) {
		for (PRequestFilter f : list) {
			setFilter(f);
		}
	}

	@Override
	public boolean process(PRequestContext ctx) {
		return processFilters(ctx);
	}

	public boolean processFilters(PRequestContext ctx) {
		return filterPipeline.process(ctx);
	}

	public boolean afterProcessFilters(PRequestContext ctx) {
		return invokeCallInfo(ctx);
	}
}
